MonitorMapTable = function(mapTable){
	this.mapTable = mapTable;
	this.table = {};
	this.web = {};
};

MonitorMapTable.prototype = {
	
	/* 设置Web配置信息 */	
	setWeb:function(web){
		
		this.web = web;
		
		//初始行数
		if(this.web.rowNum == undefined){
			this.web.rowNum = 6;
		}
		
		//是否存在尾行
		if(this.web.isBottom == undefined){
			this.web.isBottom = true;
		}
		
		//是否存在颜色变化
		if(this.web.isColor == undefined){
			this.web.isColor = true;
		}
		
		//是否存在标记变化
		if(this.web.isFlag == undefined){
			this.web.isFlag = true;
		}
		
		//底部信息设置
		if(this.web.bottom == undefined){
			this.web.bottom = {};
		}
		
		//底部连接信息
		if(this.web.bottom.href == undefined){
			this.web.bottom.href = ["#"];
		}
		
		//底部展示信息
		if(this.web.bottom.lable == undefined){
			this.web.bottom.lable = ["点击查看更多信息"];
		}
		
		//DIV标示
		if(this.web.divId == undefined){
			this.web.divId = "map_div";
		}
		
		//布局设置
		if(this.web.layout == undefined){
			var num = 12 / this.mapTable.length;
			this.web.layout = [num];		
		}
	},
	
	/* 移除页面DIV信息 */
    remove:function(){
    	$('#'+this.web.divId+" div").remove();
    },
	
    /* 装载信息 */
	load:function(){
		this.remove();
		//装载
		$('#'+this.web.divId).append(this.getDivAll());
	},
	
	/* 刷新信息 */
	refresh:function(){
		this.load();
	},
	
	/* 获取所有DIV信息 */
	getDivAll:function(){
		var div = "";
		for(var i=0;i<this.mapTable.length;i++){
			div += this.getDiv(i);
		}
		
		div += '<div class="clearfix"> </div>';
		return div;
	},
	
	/* 获取某个DIV信息 */
	getDiv:function(idx){
		
		var div = "";
		
		div += '<div class="col-md-';
		
		div += this.web.layout[idx % this.web.layout.length];
		
		div +=	'">';
		div += '<div class="stats-info">';
		
		div += this.getTitleDiv(idx);
		div += this.getDataDiv(idx);
		
		div += '</div>';
		div += '</div>';
		
		return div;
	},
	
	/* 获取标题DIV信息 */
	getTitleDiv:function(idx){
		var div = "";		
		div += '<div class="panel-heading">';
		div += '<h4 class="panel-title">'+this.mapTable[idx].title+'</h4>';
		div += '</div>';
		return div;
	},
	
	/* 获取数据DIV信息 */
	getDataDiv:function(idx){
		var div = '';
		
		div += '<div class="panel-body">';
		div += '<ul class="list-unstyled">';
		
		var length = this.mapTable[idx].data.length;
		
		for(var i=0;i<this.web.rowNum;i++){
			
			if(i < length){
				
				var status = this.mapTable[idx].data[i].status;
				
				div += '<li>';
				div += this.mapTable[idx].data[i].lable;
				div += '<div class="';
					
				if(this.web.isColor){
					if(status == "normal"){
						div += 'text-success';
					}else{
						div += 'text-danger';
					}					
				}
				
				div += ' pull-right">';
				div += this.mapTable[idx].data[i].value;
				
				if(this.web.isFlag){
					if(status == "normal"){
						div += '<i class="fa fa-level-down"></i>';
					}else{
						div += '<i class="fa fa-level-up"></i>';
					}				
				}
				
				div += '</div>';
				div += '</li>';
			}
			//填入空白
			else{
				div += '<li> &nbsp; </li>';
			}
			
		}
		
		//获取底部连接
		if(this.web.isBottom){
			div += this.getBottomDiv(idx);
		}
		
		div += '</ul>';
		div += '</div>';
		
		return div;
	},
	
	/* 获取底部DIV信息 */
	getBottomDiv:function(idx){
		var div = "";
		
		div += '<li class="last">';
		div += '<div class="text-success pull-right">';
		
		div += '<a class="cursor-pointer" href="';
		div += this.web.bottom.href[idx % this.web.bottom.href.length];
		div += '" style="text-decoration:none;">';
		div += this.web.bottom.lable[idx % this.web.bottom.lable.length];
		div += '</a>';
		
		div += '</div>';
		div += '</li>';
		
		return div;
	}

};